package cn.dengta.webapp.trade.entity;

import java.io.Serializable;
import java.util.function.Function;
import javax.annotation.Nullable;

import cn.dengta.webapp.trade.entity.meta.MetaConfig;
import com.alibaba.fastjson.JSONObject;
import lombok.*;
import me.codeplayer.util.NumberUtil;

@Getter
@Setter
public class UserLayerConfig implements MetaConfig.MetaRuleConfig {

	JSONObject rules;
	/** 所属分层ID：null 表示不区分分层 */
	@Nullable
	Integer primaryLayerId;
	String primaryLayerName;
	/** 牵线等级, 默认等级1 */
	Integer pullLevel = 1;

	@Setter(AccessLevel.NONE)
	public Object weight;

	public Object weight(boolean maleOrFemale) {
		return maleOrFemale ? new MaleWeight(primaryLayerId, this.pullLevel) : new FemaleWeight(primaryLayerId, this.pullLevel);
	}

	@Override
	public void validate() {
	}

	@Override
	public void init(MetaConfig.MetaRuleConfig config) {
	}

	static final Function<Object, Comparable<?>> castLong = i -> NumberUtil.getLong(i, null);


	@Getter
	@Setter
	public static class MaleWeight implements Serializable {

		/** 白名单权重 */
		public int whitelist = 20;
		/** 完善资料权重 */
		public int info = 5;
		/* 登陆时间权重 **/
		public int loginTime = 15;
		/** 用户分层权重值 */
		public int userLayer = 60;
		/** 所属分层ID，为 null 标识不限分层 */
		public Integer layerId;
		/** 所属分层名称 */
		public String layerName;
		/** 推荐等级 */
		public Integer pullLevel;

		public MaleWeight(Integer layerId, Integer pullLevel) {
			this.layerId = layerId;
			this.pullLevel = pullLevel;
		}

	}

	@Getter
	@Setter
	public static class FemaleWeight implements Serializable {

		/** 今日被搭讪次数 */
		public int greetNum = 10;
		/** 今日被搭讪大于等于次数时的权重 */
		public int greet = 20;
		/** 上传头像权重 */
		public int avatar = 5;
		/* 登陆时间权重 **/
		public int loginTime = 15;
		/** 用户分层权重值 */
		public int userLayer = 60;
		/** 所属分层ID，为 null 标识不限分层 */
		public Integer layerId;
		/** 所属分层名称 */
		public String layerName;
		/** 推荐等级 */
		public Integer pullLevel;

		public FemaleWeight(Integer layerId, Integer pullLevel) {
			this.layerId = layerId;
			this.pullLevel = pullLevel;
		}

	}

}
